/**
 * 
 */
package oop.ex2.util;
import java.io.*;

import oop.ex2.util.exceptions.ReaderIOException;
/**
 * this class extends the ability of bufferedReader, it returns an iterator
 * to go through the file system. 
 * @author liorz06
 * @author ohad_dan
 */
public class FilterReader {
	//***********************************************************************
	//  Data members :                                                      *
	//***********************************************************************
	private String _source;
    private BufferedReader _reader; 
    //***********************************************************************
	//  Methods :                                                           *
	//***********************************************************************
   /**
    * Constructs a new filter reader.
    * @param source File's Source directory.
    * @throws ReaderIOException In case of I/O failure.
    */
    public FilterReader(String source) throws ReaderIOException{
        _source = source;
        try{
            _reader = new BufferedReader( new FileReader( _source ) );
        }
        catch( IOException e) {
            throw new ReaderIOException("Error:I/O failure");
        }
    }
    /**
     * Returns an iterator over the file collection.
     * @return An iterator over the file collection.
     * @throws ReaderIOException In case of I/O failure.
     */
    public FileIterator iterator() throws ReaderIOException{
        return new FileReaderIterator(_reader);
    }
    /**
     * Close the reader.
     * @throws ReaderIOException In case of I/O failure.
     */
    public void close() throws ReaderIOException{
        try{
            _reader.close();
        }
        catch( IOException e ) {
            throw new ReaderIOException("Error:I/O failure");
        }
    }
}
